package org.example.controller;

import lombok.Getter;
import org.example.model.User;
import org.example.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/8/8
 * Time:15:48
 **/
@Getter
@Controller
public class LoginController {

    //对象注入的3种方式（从spring获取对象）
//    //第一种注入方式：属性注入
//    @Autowired
//    private LoginService loginService;//变量名（loginService）不可随意取

//    @Autowired
//    @Qualifier("loginService")//随意取的条件
//    private LoginService ls;

    //第二种注入方式：通过set的方式注入
//    private LoginService loginService;
//    @Autowired//不可不加
//    public void setLoginService(LoginService loginService) {//变量名可随意起
//        this.loginService = loginService;
//    }

    //第三种注入方式：构造函数注入
    private LoginService loginService;
    @Autowired//可不加
    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }

    public void sayHi(){
        //参数效验
        loginService.sayHi();
    }
    @Bean
    public User user1() {
        User user = new User();
        user.setName("姜云升");
        user.setPassword("哈哈哈");
        return user;
    }

    @Bean
    public User user2() {
        User user = new User();
        user.setName("姜云");
        user.setPassword("hhh");
        return user;
    }
}
